<?php
/**
 * 用户列表页模板
 */

use yii\helpers\Html;
use kartik\grid\GridView;
use common\models\DAO\UserRole;

$this->title = '用户列表';

$gridColumns = [
    ['class' => 'kartik\grid\SerialColumn'],
    [
        'attribute' => 'tradeID',
        'class' => 'common\widgets\KartikUserColumn',
    ],
    'realName',
    [
        'label' => '推荐人交易号',
        'attribute' => 'paterID',
        'value' => 'paterUser.tradeID',
    ],
    [
        'label' => '注册来源',
        'attribute' => 'place',
        'value' => function ($model) {
            $data[1] = "安卓";
            $data[2] = "ios";
            $data[3] = "客户端";
            $data[4] = "Web端";
            $data[5] = "手机端";
            $data[6] = "mac";
            return $data[$model->place];
        },
        'filter' => [
            1 => '安卓',
            2 => 'ios',
            3 => '客户端',
            4 => 'Web端',
            5 => '手机端',
            6 => 'mac',
        ]
    ],
    'phone',
    'orgCode',
    [
        'label' => '用户级别',
        'attribute' => 'roleID',
        'value' => function($model){
            return UserRole::getNameByID($model->id);
        },
        'filter' => UserRole::getSimpleList(),
    ],
    [
        'attribute' => 'signTime',
        'value' => function ($model) {
            if ($model->signTime > 0) {
                return  date("Y-m-d H:i:s",$model->signTime);
            } else {
                return "未签约";
            }
        },
        'filter' => [
            2 => "未签约",
            1 => "已签约",

        ]
    ],
    [
        'label' => '用户余额',
        'value' => function($model){
            return $model->totalRemainder();
        }
    ],
    [
        'format' => 'datetime',
        'attribute' => 'createTime',
        'filterType' => GridView::FILTER_DATE_RANGE,
        'filterWidgetOptions' => [
            'presetDropdown' => true,
            'pluginOptions' => [
                'locale' => [
                    'format' => 'YYYY/MM/DD',
                    'separator' => ' ~ ',
                    'language' => 'zh-CN',
                ]
            ],
            'pluginEvents' => [
                "apply.daterangepicker" => "function(){ aplicarDateRangeFilter('createTime') }",
            ],
        ],
    ],

];

echo GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'toolbar' => [
        ['content' => Html::a('<i class="glyphicon glyphicon-plus"></i> 添加会员', ['user/add'], ['class' => 'btn btn-primary'])],
        '{toggleData}'
    ],
    'panel' => [
        'type' => GridView::TYPE_DEFAULT,
        'heading' => $this->title,
    ],
    'columns' => $gridColumns,
]);